#include "stdafx.h"
#include "CppUnitTest.h"

#include "PluginICPsample.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace PluginICPsampleTest
{		
	TEST_CLASS(UnitTest1)
	{
	public:
		
		private:
		PluginICPsample	*_lib;

		public:
			TEST_METHOD_INITIALIZE(InitPluginICPsample)
			{
				_lib = new PluginICPsample();
			}

			TEST_METHOD_CLEANUP(DeinitPluginICPsample)
			{
				if (_lib != nullptr)
					delete _lib;
				_lib = nullptr;
			}

			TEST_METHOD(CreatePluginICPsampleTest)
			{
				Assert::IsNotNull(_lib);
			}

			TEST_METHOD(PluginICPsampleInfoTest)
			{
				std::string temp;
				Assert::IsTrue(MxGUID::IsEqual( PRODID_PluginICPsample, MxGUID::ConvertFromString( "{F3E44D51-100B-4240-9ECA-5DAA26D5B7B5}")));

		//IMxPluginBase
				Assert::IsTrue(MxGUID::IsEqual(IPluginICPsampleIID::Guid(), _lib->GetInterfaceGUID()));
				Assert::AreEqual(IPluginICPsampleIID::Name(), _lib->GetInterfaceName());
		//IMxPluginLibDetails
				Assert::AreEqual("PluginICPsample", _lib->GetLibName());
				Assert::AreEqual("Sample MxPluginForImages - example implementation of Image Compute interfaces", _lib->GetLibDescription());
				Assert::AreEqual("1.2.32.0", _lib->GetLibVersion());
				Assert::AreEqual("MPT-Dev", _lib->GetLibOwnerName());
				Assert::AreEqual("Copyright (C) 2015 Will Stott",_lib->GetLibCopyrightNotice());
				Assert::AreEqual("{F3E44D51-100B-4240-9ECA-5DAA26D5B7B5}",_lib->GetLibID());
				Assert::AreEqual("http://www.mxplugin.org/plugins/support/MPT-Dev/ICPsample",_lib->GetLibSupportSite());
				Assert::AreEqual("New BSD Licence",_lib->GetLibLicenseName());
				Assert::AreEqual("http://www.mxplugin.org/plugins/license/MPT-Dev/ICPsample",_lib->GetLibLicenseURL());
				std::wstring pathfilename(_lib->GetLibPathFilename());
				Assert::IsTrue(pathfilename.find(L"PluginICPsample.dll") != std::wstring::npos);
				Assert::IsTrue(MxGUID::IsEqual(SID_Universal,_lib->GetSocketID()));
		//IPluginStdDetailsLib
				Assert::AreEqual("hello from PluginICPsample",_lib->GetComment());
			}

		TEST_METHOD(IMxPluginBaseTest)
		{
			IMxPluginBase *base = static_cast<IMxPluginBase *>(::CreateClassInstance( GUID_Invalid ));
			Assert::IsNull(base);

			base = static_cast<IMxPluginBase *>(::CreateClassInstance(IMxPluginBaseIID::Guid()));

			Assert::IsNotNull(base);
			Assert::IsTrue(MxGUID::IsEqual(IPluginICPsampleIID::Guid(), base->GetInterfaceGUID()));
			Assert::AreEqual(IPluginICPsampleIID::Name(), base->GetInterfaceName());
	
			IMxPluginLibDetails *details = static_cast<IMxPluginLibDetails *>(base->Dynamic_cast(IMxPluginLibDetailsIID::Guid()));
			Assert::IsNotNull(details);
			Assert::AreEqual("{F3E44D51-100B-4240-9ECA-5DAA26D5B7B5}", details->GetLibID());
			Assert::AreEqual(1L, details->DestroyPtr());
			details = nullptr;

			IMxPluginBase *base2 = base;
			base->DuplicatePtr();
			Assert::AreEqual(1L, base2->DestroyPtr());
			base2 = nullptr;

			Assert::IsNotNull(base);
			Assert::IsTrue(MxGUID::IsEqual(IPluginICPsampleIID::Guid(), base->GetInterfaceGUID()));
			Assert::AreEqual(IPluginICPsampleIID::Name(), base->GetInterfaceName());
	
			Assert::AreEqual(0L, base->DestroyPtr());
			base = nullptr;
		}

		TEST_METHOD(IMxPluginLibDetailsTest)
		{
			IMxPluginLibDetails *details = static_cast<IMxPluginLibDetails *>(::CreateClassInstance(IMxPluginLibDetailsIID::Guid()));

			Assert::IsNotNull(details);

			Assert::AreEqual("{F3E44D51-100B-4240-9ECA-5DAA26D5B7B5}", details->GetLibID());
			Assert::AreEqual("PluginICPsample",details->GetLibName());
			Assert::AreEqual("1.2.32.0", details->GetLibVersion());
			Assert::AreEqual("Sample MxPluginForImages - example implementation of Image Compute interfaces", details->GetLibDescription());
			Assert::AreEqual("http://www.mxplugin.org/plugins/support/MPT-Dev/ICPsample", details->GetLibSupportSite());
			Assert::IsTrue(MxGUID::IsEqual(SID_Universal, details->GetSocketID()));

			Assert::AreEqual("MPT-Dev",details->GetLibOwnerName());
			Assert::AreEqual("Copyright (C) 2015 Will Stott", details->GetLibCopyrightNotice());
	
			Assert::AreEqual("New BSD Licence", details->GetLibLicenseName());
			Assert::AreEqual("http://www.mxplugin.org/plugins/license/MPT-Dev/ICPsample", details->GetLibLicenseURL());

			Assert::AreNotEqual(L"[invalidPathFilename]", details->GetLibPathFilename());

			Assert::AreEqual(0L, details->DestroyPtr());
			details = nullptr;
		}

		TEST_METHOD(IPluginICPsampleTest)
		{
			IPluginICPsample *sample = static_cast<IPluginICPsample *>(::CreateClassInstance(IPluginICPsampleIID::Guid()));

			Assert::IsNotNull(sample);

			Assert::AreEqual("{F3E44D51-100B-4240-9ECA-5DAA26D5B7B5}", sample->GetLibID());  //PRODID_PluginICPsample =	{F3E44D51-100B-4240-9ECA-5DAA26D5B7B5}

			Assert::AreEqual(0L, sample->DestroyPtr());
			sample = nullptr;
		}
	};
}